﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using SGCG.Helpers;

namespace SGCG.Model
{
    public class RotateTransform : TransformBase
    {

        private Point relativeTo = new Point(0, 0);
        public Point RelativeTo
        {
            get { return relativeTo; }
            set
            {
                relativeTo = value;
                OnTransformChanged();
            }
        }

        private double angle = 0;
        public double Angle
        {
            get { return angle; }
            set
            {
                angle = value;
                OnTransformChanged();
            }
        }

        public static Point Rotate(Point point, Point relativeTo, double angle)
        {
            return Rotate(point.Subtract(relativeTo), angle).Add(relativeTo);
        }

        public static Point Rotate(Point point, double angle)
        {
            return new Point(point.X * Math.Cos(angle) - point.Y * Math.Sin(angle),
                             point.X * Math.Sin(angle) + point.Y * Math.Cos(angle));
        }

        public override Point Transform(Point point)
        {
            return Rotate(point, RelativeTo, Angle);
        }

        public override void Transform(double angleInit, double angleSpan, out double newAngleInit, out double newAngleSpan)
        {
            newAngleSpan = angleSpan;
            newAngleInit = ((angleInit + Angle) % (2 * Math.PI) + 2 * Math.PI) % (2 * Math.PI);
        }

    }
}
